import { PolyLineToolProps, LineProps } from '../types';
// LineProps
// 返回处理好的点线数据
// export const addLinToMap = (pointArr: LineProps[]) => {
//   const points = pointArr.map((i: LineProps) => new T.LngLat(i.longitude, i.latitude));
//   const line = new T.PolylineTool(points);
//   return line;
// };

function usePolylineTool(config: PolyLineToolProps) {
  const { Map, lineStyle } = config;
  // 创建画线工具
  const createPolyLineTool = () => {
    return new T.PolylineTool(Map, lineStyle);
  };

  const polylineTool = createPolyLineTool();

  // 添加点线
  const addLineToMap = (pointArr: LineProps[]) => {
    const points = pointArr.map((i: LineProps) => new T.LngLat(i.longitude, i.latitude));
    const line = new T.PolylineArrow(points, lineStyle);
    return line;
  };
  // 清除覆盖物 line覆盖物对象
  const removeLineToMap = (line: any) => {
    console.log(`被清除的覆盖物对象====================`, line);
    if (!line) return;
    Map.removeOverLay(line);
  };

  return [polylineTool, { addLineToMap, removeLineToMap }];
}

export default usePolylineTool;
